package com.example.demo.mapper;

import com.example.demo.pojo.Comment;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @author yanglup
 * @create 2020-12-13 20:28
 */
@Mapper
public interface CommentMapper {
    /**添加评论*/
    @Insert("insert into commentliattable (openid, comment_time, comment_text, nickName, likenumber,avatarUrl,goods_id) " +
            "values (#{openid},#{comment_time},#{comment_text},#{nickName},#{likenumber},#{avatarUrl},#{goods_id});")
    void commonentadd(String openid,String comment_time,String comment_text,String nickName,Integer likenumber,String avatarUrl,Integer goods_id);

    /**查询评论列表*/
    @Select("select * from commentliattable where goods_id=#{goods_id}")
    List<Comment> commonentlist(Integer goods_id);

    /**查询评论列表数量*/
    @Select("select count(*) from commentliattable where goods_id=#{goods_id}")
    Integer commonentnumbers(Integer goods_id);


    /**查询是否like过*/
    @Select("select * from commentliattable where comment_id=#{comment_id}")
    Comment commentidcheck(Integer comment_id);
    /**如果没找到就添加like*/
    @Update("update commentliattable set likenumber=likenumber+1 where comment_id=#{comment_id}")
    void commonentlikenumber(Integer comment_id);


    /*********************************************评论后台管理平台*******************************************************************/
    /**后台查询评论列表*/
    @Select("select * from commentliattable ")
    List<Comment> Commentlist();
    /**查询评论列表数量*/
    @Select("select count(*) from commentliattable ")
    Integer Commentlistnumber();

    /**删除评论*/
    @Delete("delete from commentliattable where comment_id=#{comment_id}")
    void Commentdelete(Integer comment_id);

    /**搜索*/
    @Select("select * from commentliattable where comment_text like CONCAT('%',#{comment_text},'%')")
    List<Comment> Commentlistquery(String comment_text);
    /**搜索数量*/
    @Select("select count(*) from commentliattable where comment_text like CONCAT('%',#{comment_text},'%')")
    Integer Commentlistquerynumber(String comment_text);
}
